home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Apple Shared Library Manager / ASLM Examples / TestTools / Sources / TestNoVTable.cp < prev    next >
Encoding:
Text File  |  1996-11-19  |  2.9 KB  |  139 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TestNoVTable.cp
  3.  
  4.     Contains:    Implementation of class TTestNoVTable
  5.  
  6.     Copyright:    © 1992-1994 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10. #ifndef __TESTNOVTABLE__
  11. #include "TestNoVTable.h"
  12. #endif
  13. #ifndef __MISCTESTS__
  14. #include "MiscTests.h"
  15. #endif
  16.  
  17. static TNoVTable    gTemp(7);
  18. static TStdVTable    gStdTemp(25);
  19.  
  20. TTestNoVTable::TTestNoVTable()
  21. {}
  22.  
  23. TTestNoVTable::~TTestNoVTable()
  24. {}
  25.  
  26. void TTestNoVTable::InitTest(BooleanParm, BooleanParm, int, char**)
  27. {}
  28.  
  29. void TTestNoVTable::EndTest(BooleanParm, BooleanParm)
  30. {}
  31.  
  32. void TTestNoVTable::RunTestIteration(BooleanParm verbose, BooleanParm debug)
  33. {
  34.     Boolean    ok = true;
  35.     unsigned long    elapsed;
  36.  
  37.     if (verbose)
  38.         Printf("### INFO: Testing static object with no VTable\n");
  39.     long val = gTemp.Add(4);
  40.     if (val != 11)
  41.     {
  42.         Printf("### ERROR: Expected 11 from Add, got %ld\n", val);
  43.     }
  44.     if (verbose)
  45.         Printf("### INFO: Testing auto object with no VTable\n");
  46.     {
  47.         TNoVTable    test(5);
  48.         
  49.         val = test.Add(4);
  50.         if (val != 9)
  51.         {
  52.             ok = false;
  53.             Printf("### ERROR: Expected 9 from TNoVTable::Add, got %ld\n", val);
  54.         }
  55.         val = test.Sub(7);
  56.         if (val != 2)
  57.         {
  58.             ok = false;
  59.             Printf("### ERROR: Expected 2 from TNoVTable::Sub, got %ld\n", val);
  60.         }
  61.         if (ok)
  62.         {
  63.             TStopwatch    theStamp;
  64.             for (size_t idx = 0; idx < 1000; ++idx)
  65.             {
  66.                 val = test.Add(0);
  67.             }
  68.             elapsed = (&theStamp)->ElapsedMicroseconds();
  69.         }
  70.     }
  71.     if (ok)
  72.         Printf("### INFO: 1000 iterations for TNoVTable took %lu microseconds\n", elapsed);
  73.  
  74.     if (debug)
  75.         DebugBreak("About to test TStdVTable");
  76.         
  77.     if (verbose)
  78.         Printf("### INFO: Testing static object with standard VTable\n");
  79.     val = gStdTemp.Add(4);
  80.     if (val != 29)
  81.     {
  82.         Printf("### ERROR: Expected 29 from TStdVTable::Add, got %ld\n", val);
  83.     }
  84.     if (verbose)
  85.         Printf("### INFO: Testing auto object with standard VTable\n");
  86.     {
  87.         TStdVTable    test(9);
  88.         val = (&test)->Add(4);
  89.         if (val != 13)
  90.         {
  91.             ok = false;
  92.             Printf("### ERROR: Expected 13 from TStdVTable::Add, got %ld\n", val);
  93.         }
  94.         val = (&test)->Sub(7);
  95.         if (val != 6)
  96.         {
  97.             ok = false;
  98.             Printf("### ERROR: Expected 6 from TStdVTable::Sub, got %ld\n", val);
  99.         }
  100.         if (ok)
  101.         {
  102.             TStopwatch    theStamp;
  103.             for (size_t idx = 0; idx < 1000; ++idx)
  104.             {
  105.                 val = (&test)->Add(0);
  106.             }
  107.             elapsed = (&theStamp)->ElapsedMicroseconds();
  108.         }
  109.         if (ok)
  110.             Printf("### INFO: 1000 iterations for TStdObject through the vtable took %lu microseconds\n", elapsed);
  111.     }
  112.     {
  113.         TStdVTable    test(11);
  114.         val = test.Add(4);
  115.         if (val != 15)
  116.         {
  117.             ok = false;
  118.             Printf("### ERROR: Expected 15 from TStdVTable::Add, got %ld\n", val);
  119.         }
  120.         val = test.Sub(7);
  121.         if (val != 8)
  122.         {
  123.             ok = false;
  124.             Printf("### ERROR: Expected 8 from TStdVTable::Sub, got %ld\n", val);
  125.         }
  126.         if (ok)
  127.         {
  128.             TStopwatch    theStamp;
  129.             for (size_t idx = 0; idx < 1000; ++idx)
  130.             {
  131.                 val = test.Add(0);
  132.             }
  133.             elapsed = (&theStamp)->ElapsedMicroseconds();
  134.         }
  135.         if (ok)
  136.             Printf("### INFO: 1000 iterations for TStdObject through stubs took %lu microseconds\n", elapsed);
  137.     }
  138. }
  139.